#ifndef CHINACTPQUOTETHREAD_H
#define CHINACTPQUOTETHREAD_H


#include <QThread>
#include <QObject>
#include "chinactprealtime.h"

// 行情管理类（负责在独立线程中运行API）
class ChinactpQuoteThread : public QThread {
    Q_OBJECT

public:
    explicit ChinactpQuoteThread(QObject *parent = nullptr);
    ~ChinactpQuoteThread() override;

    // 启动行情服务
    void startMd(const QString &frontAddr,const QStringList &instrunments);

    // 停止行情服务
    void stopMd();

signals:
    // 转发 MdSpi 的信号到主线程
    void connected();
    void disconnected(int reason);
    void loginResult(bool success, const QString &msg);
    void marketDataReceived(const QString &instrumentID, double lastPrice, double askPrice, double bidPrice);

protected:
    void run() override;  // 线程入口
    QStringList instrumentList;

private:
    CThostFtdcMdApi *m_mdApi = nullptr;
    ChinactpRealtime *m_mdSpi = nullptr;
    QString m_frontAddr;  // 行情前置地址
    bool m_running = false;
};

#endif // CHINACTPQUOTETHREAD_H
